package com.pucheng.bracelet.data.bean

import androidx.room.*
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken

@Entity(tableName = "hert_rate2")
@TypeConverters(HertRateNodeConverters::class)
data class AllHertRateBean(
    @PrimaryKey var date: String = "",
    @ColumnInfo var timestamp:Long = System.currentTimeMillis(),//睡眠时间
    @ColumnInfo var averageHR:Int = 0,//平均心率
    @ColumnInfo var nodes:List<HertRateNode> = arrayListOf()
)

class HertRateNodeConverters {

    @TypeConverter
    fun stringToObject(value: String): List<HertRateNode> {
        val listType = object : TypeToken<List<HertRateNode>>() {

        }.type
        return Gson().fromJson(value, listType)
    }

    @TypeConverter
    fun objectToString(list: List<HertRateNode>): String {
        val gson = Gson()
        return gson.toJson(list)
    }
}

data class HertRateNode(var min_offset:Int=0 ,var bpm:Int = 0)